import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;


public class IndexHeader 
{
	public void writeHeader(index i, long t[]) 
	{
		
		RandomAccessFile fi;
		try {
			 fi = new RandomAccessFile(i.fo, "rw");
			 long pos = 0;
			 for(int j=0;j<t.length;j++)
			 {
				 fi.seek(pos);
				 fi.writeLong(t[j]);
				 pos += 8;
			 }
			 fi.close();
			 
		}
		catch (Exception e) {
			e.printStackTrace();
		}	
	}
	
	public void writeHeader(index i) 
	{
		
		RandomAccessFile fi;
		try {
			 fi = new RandomAccessFile(i.fo, "rw");
			 long pos = 0;
				 fi.seek(pos);
				 fi.writeLong(i.totalSize);
				 fi.writeLong(i.actualSize);
				 fi.writeLong(i.nextpointer);
				 fi.writeLong(i.blockLength);
				 fi.writeLong(i.freelist);
				 fi.writeLong(i.endpoint);
			 fi.close();
			 
		}
		catch (Exception e) {
			e.printStackTrace();
		}	
	}
	
	public long[] readHeader(File file) throws Exception
	{
		long[] header =  new long[6];
		RandomAccessFile fi = new RandomAccessFile(file, "rw");
		int pos = 0;
		for(int i=0;i<header.length;i++)
		{
			fi.seek(pos);
			header[i] = fi.readLong();
			pos = pos + 8;
		}
		fi.close();
		return header;
	}
}
